package com.lanhai.fnstore.log;
 
import com.lanhai.fnstore.Tools;
import com.lanhai.fnstore.dispatch.AgvData;
import com.lanhai.fnstore.push.MsgData;
import com.lanhai.fnstore.thirdpart.StationData;

/**
 * 日志项
 * @author virus408
 *
 */
public class LogData {
	private int agvId;
	private int  cmdtype; //0=小车 1=对接设备
	private String ip;  
	private String sendRemark;
	private String sendData; 
	private String receiveData;
	private String receiveRemark;
	private long  createTime;  
	private int line;
	
	
	
	public int getCmdtype() {
		return cmdtype;
	}

	public void setCmdtype(int cmdtype) {
		this.cmdtype = cmdtype;
	}

	public LogData() { 
		createTime=System.currentTimeMillis();
	}
	
	public static LogData fromMsgData(int line, MsgData data) {
		LogData obj=new LogData();
		obj.setAgvId(data.getAgvId());
		if(data.getAgvId()==0) {
			obj.setCmdtype(0);
		}else {
			obj.setCmdtype(1);
		} 
		obj.setLine(line);
		obj.setIp(data.getIp()); 
		obj.setReceiveData("");
		obj.setReceiveRemark("");
		 
		obj.setSendData(Tools.byte2HexStr(data.getData()));
		obj.setSendRemark(data.getRemark());
		return obj;
	}

	
	
	public static LogData fromAgv (AgvData data  ) {
		LogData obj=new LogData();
		obj.setAgvId(data.getAgvId());
		obj.setIp(""); 
		obj.setCmdtype(0);
		obj.setLine(0); 
		obj.setReceiveData( data.getCmdStr());
		obj.setReceiveRemark(data.getType().getName());
		 
		obj.setSendData("");
		obj.setSendRemark("");
		return obj;
	}
	
	public static LogData fromStation(StationData data ,String ip) {
		LogData obj=new LogData();
		obj.setAgvId(0);
		obj.setCmdtype(1);
		obj.setIp(ip); 
		obj.setReceiveData( data.getCmdStr());
		obj.setReceiveRemark(data.getEventType().getEventName());
		 obj.setLine(data.getLine());
		obj.setSendData("");
		obj.setSendRemark("");
		return obj;
	}


	public int getAgvId() {
		return agvId;
	}



	public void setAgvId(int agvId) {
		this.agvId = agvId;
	}



	public String getIp() {
		return ip;
	}



	public void setIp(String ip) {
		this.ip = ip;
	}
 
	public String getSendRemark() {
		return sendRemark;
	}



	public void setSendRemark(String sendRemark) {
		this.sendRemark = sendRemark;
	}



	public String getSendData() {
		return sendData;
	}
 
 

	public void setSendData(String sendData) {
		this.sendData = sendData;
	}
 
	public String getReceiveData() {
		return receiveData;
	}

  
	public void setReceiveData(String receiveData) {
		this.receiveData = receiveData;
	}



	public String getReceiveRemark() {
		return receiveRemark;
	}



	public void setReceiveRemark(String receiveRemark) {
		this.receiveRemark = receiveRemark;
	}



	public int getLine() {
		return line;
	}

	public void setLine(int line) {
		this.line = line;
	}

	public long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}

	@Override
	public String toString() {
		String s;
		if(agvId==0) {
			//station
			if(receiveRemark.isBlank()) {
				//发送
				s=String.format("IP:【%s】,发送指令:【%s】, %s", ip,sendRemark,sendData);
			}else {
				//接收
				s=String.format("IP:【%s】,收到指令:【%s】, %s", ip,receiveRemark,receiveData);
			}
		
		}else {
			//agv
			if(receiveRemark.isBlank()) {
				//发送
				s=String.format("车号:【%d】,发送指令:【%s】, %s", ip,sendRemark,sendData);
			}else {
				//接收
				s=String.format("车号:【%d】,收到指令:【%s】, %s", agvId,receiveRemark,receiveData);
			} 
		} 
		return s;
	}
	
	
	 
}
